<?php

	/**
	 * @see Zend_Controller_Front
	 */
	require_once 'Zend/Controller/Front.php';
	
	
	class Bike_Controller_Front extends Zend_Controller_Front
	{
	    protected $_modules;
	    
	    public function setModules(Bike_Db_Table_Rowset $modules)
	    {
	    	$this->_modules = $modules;
	    	return $this;
	    }
	    
	    public function getModules()
	    {
	    	return $this->_modules;
	    }
		
		public static function getInstance()
	    {
	        if (null === self::$_instance) {
	            self::$_instance = new self();
	        }
	
	        return self::$_instance;
	    }
	
	    public function getModulesDirectory()
	    {
	    	return dirname($this->getModuleDirectory());
	    }
	
	    /**
	     * Return the dispatcher object.
	     *
	     * @return Zend_Controller_Dispatcher_Interface
	     */
	    public function getDispatcher()
	    {
	        /**
	         * Instantiate the default dispatcher if one was not set.
	         */
	        if (!$this->_dispatcher instanceof Zend_Controller_Dispatcher_Interface)
	        {
	            $this->_dispatcher = new Bike_Controller_Dispatcher();
	        }
	        return $this->_dispatcher;
	    }
	
	    public function getRequest()
	    {
	    	if(!$this->_request instanceof Zend_Controller_Request_Abstract)
	    	{
	    		$this->_request = new Bike_Controller_Request_Http();
	    	}
	    	return $this->_request;
	    }
	
	    public function getRouter()
	    {
	        if(is_null($this->_router))
	        {
	            $this->setRouter(new Bike_Controller_Router());
	        }
	        return $this->_router;
	    }
	
	    public function getBootstrap()
	    {
	    	 $bootstrap = $this->getParam('bootstrap');
	    	 if(!$bootstrap instanceof Zend_Application_Bootstrap_BootstrapAbstract)
	    	 {
	    	 	Throw new Bike_Controller_Exception('Bootstrap is not instance of Zend_Application_Bootstrap_BootstrapAbstract');
	    	 }
	    	 return $bootstrap;
	    }
	
	    public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
	    {
	    	Bike_Timer::start('dispatch');
	    	$return = parent::dispatch($request, $response);
	    	Bike_Timer::stop('dispatch');
	    	return $return;
	    }
	
	}

